package com.junzhiit.nengji.shop.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.bainaeco.framework.base.dao.AbstractBaseDAO;
import com.bainaeco.framework.common.jdbc.StatementParameter;
import com.bainaeco.framework.enums.IsDelete;
import com.junzhiit.nengji.shop.dao.ChainSkuContentDAO;
import com.junzhiit.nengji.shop.model.ChainSkuContent;
import com.junzhiit.nengji.shop.model.enums.SkuContentStatus;

@Repository
public class ChainSkuContentDAOImpl extends AbstractBaseDAO<ChainSkuContent> implements ChainSkuContentDAO{

	@Override
	public List<ChainSkuContent> querySkuContent(String chainGoodsId) {
		String sql = "select * from chain_sku_content where is_delete=? and chain_goods_id=? order by standards,status desc";

		StatementParameter param = new StatementParameter();
		param.setInt(IsDelete.NO.toIntValue());
		param.setString(chainGoodsId);

		return queryForList(sql, ChainSkuContent.class, param);
	}

	@Override
	public List<ChainSkuContent> findAllByGoodsId(String chainGoodsId, int pageNumber, int maxPageRow) {
		String sql = "select * from chain_sku_content where is_delete=? and chain_goods_id=?";

		StatementParameter param = new StatementParameter();
		param.setInt(IsDelete.NO.toIntValue());
		param.setString(chainGoodsId);

		return super.queryForPagingList(sql, ChainSkuContent.class, param, pageNumber, maxPageRow);
	}

	@Override
	public int getTotalCountByGoodsId(String chainGoodsId) {
		
		String sql = "select count(*) from chain_sku_content where is_delete=? and chain_goods_id=?";

		StatementParameter param = new StatementParameter();
		param.setInt(IsDelete.NO.toIntValue());
		param.setString(chainGoodsId);

		return super.queryForInt(sql, param);
	}

	@Override
	public boolean deleteSkuContent(String chainGoodsId) {
		String sql = "delete from chain_sku_content where is_delete=? and chain_goods_id=?";

		StatementParameter param = new StatementParameter();
		param.setInt(IsDelete.NO.toIntValue());
		param.setString(chainGoodsId);

		return updateForBoolean(sql, param);
	}

	@Override
	public List<ChainSkuContent> findSkuContentByGoodsId(String chainGoodsId) {
		String sql = "select * from chain_sku_content where is_delete=? and status=? and chain_goods_id=? order by standards,status desc";

		StatementParameter param = new StatementParameter();
		param.setInt(IsDelete.NO.toIntValue());
		param.setInt(SkuContentStatus.ACTIVE.toIntStatus());
		param.setString(chainGoodsId);

		return queryForList(sql, ChainSkuContent.class, param);
	}

}
